<template>
  <el-dialog :title="info.title" :visible.sync="visible" center width="460px" :before-close="handleCancel">
    <el-form ref="formDate" label-suffix=":" label-width="120px" :rules="rules" :model="form">
      <el-row>
        <el-col :span="24">
          <el-form-item label="人员姓名" prop="cost">
            <el-input v-model="form.cost" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="人员身份证" prop="cost">
            <el-input v-model="form.cost" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="安全员姓名" prop="cost">
            <el-input v-model="form.cost" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="安全员身份证" prop="cost">
            <el-input v-model="form.cost" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark" style="width: 100%">
            <el-input type="textarea" :rows="4" v-model="form.remark" size="small" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="fr mt10">
            <el-button size="small" @click="handleCancel()">取 消</el-button>
            <el-button type="primary" size="small" @click="handleEdit()">保 存</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
import { selStaff, queryStaffById } from '@/api/staff'

export default {
  props: {
    info: {
      type: Object,
      default: null
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  data() {
    return {
      customers: [],
      staffs: [],
      form: {},
      types: [{key: '0', value: '否'}, {key: '1', value: '是'}],
      rules: {
        name: [{ required: true, trigger: 'blur', message: '客户名称不可为空' }]
      },
      visible: false
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.form = this.info.edit
        if (this.info.type === 'edit') {
          this.staff()
        }
      }
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  mounted() {
  },
  methods: {
    handleEdit() {
      this.$refs['formDate'].validate(async(valid) => {
        if (valid) {
          this.$message.success('成功')
          // if (this.info.type === 'add') {
          //   addPro(this.form).then(response => {
          //     this.getData()
          //     this.handleCancel()
          //     this.$message.success('添加成功')
          //   }).catch(err => {
          //     this.$message.error(err.msg)
          //   })
          // } else {
          //   upPro(this.form).then(response => {
          //     this.getData()
          //     this.handleCancel()
          //     this.$message.success('编辑成功')
          //   }).catch(err => {
          //     this.$message.error(err.msg)
          //   })
          // }
        }
      })
    },
    selStaff(query) {
      let str = ''
      // if (Object.prototype.toString.call(query) === '[object String]') str = query
      // selStaff({ name: str }).then(response => {
      //   this.staffs = response.list
      // }).catch(err => {
      //   this.$message.error(err.msg)
      // })
    },
    staff() {
      this.$set(this, 'staffs', [])
      // queryStaffById({ id: this.form.su_track }).then(response => {
      //   const info = {}
      //   info.key = response.staff.id
      //   info.value = response.staff.nickname
      //   this.staffs.push(info)
      // }).catch(err => {
      //   this.$message.error(err.msg)
      // })
    },
    handleCancel(done) {
      if (this.$refs['formDate']) this.$refs['formDate'].resetFields()
      if (done && typeof done === Function) {
        done()
      } else {
        this.visible = false
      }
    }
  }
}
</script>

<style>

</style>
